import {reqCategory2} from '../../api/index';

Page({
  data: {
    currentIndex: 0, //左侧菜单高亮标记
    categoryArr:[],
  },
  onLoad() {
    // 获取二级分类数据
    this.getCategory2();
  },
  // 点击左侧分类高亮
  changeActive(event) {
    this.setData({
      currentIndex: event.currentTarget.dataset.index
    })
  },
  // 获取二级分类数据
  async getCategory2() {
    const result = await reqCategory2();
    if (result.code === 200) {
      this.setData({
        categoryArr: result.data,
      })
    }
  },
  // 跳转到详细数据列表
  goGoodsList(event){
    const category2Id = event.currentTarget.dataset.id;
    // 页面跳转需要三级分类
    wx.navigateTo({
      // 带着二级分类ID
      url: `/pages/goodsList/goodsList?category2Id=${category2Id}`,
    })
  }
})